package com.woniuxy.springboot.mybatis.controller;

import com.woniuxy.springboot.mybatis.pojo.User;
import com.woniuxy.springboot.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/users")
public class ThymeleafUserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/userlist")
    public ModelAndView getUsers() {
        ModelAndView modelAndView = new ModelAndView();
        List<User> users = userService.selectAllUsers();
        modelAndView.addObject("users", users);
        modelAndView.setViewName("userlist");
        return modelAndView;
    }

    @RequestMapping("/test")
    public ModelAndView test() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("test");
        return modelAndView;
    }
}
